package com.happyclub.lbjcontroller;

import com.happyclub.lbj.service.IActivityService;
import com.happyclub.lbj.service.IGetHotActivityList;
import com.happyclub.pojo.TbActivity;
import com.happyclub.pojo.TbActivityPhotoAlbum;
import com.happyclub.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 高欢
 * @description 活动表
 * @date 2019/4/2
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    IActivityService iActivityService;

    @Autowired
    IGetHotActivityList IGetHotActivityList;

    @RequestMapping(value = "/saveActivity",method = RequestMethod.POST)
    public JsonResult saveActivity(@RequestBody TbActivity activity){
        return iActivityService.insertActivity(activity);
    }

    //用户选择发布活动的类型时请求
    @RequestMapping(value = "/findTeamByUser/{userId}",method = RequestMethod.GET)
    public JsonResult findTeamByUser(@PathVariable String userId){
        return iActivityService.findTeamByUser(userId);
    }

    //当选择使用相册时,查出个人的相册列表,需要发起ajax请求
    @RequestMapping(value = "/findPhotoAlbumByUserId/{userId}",method = RequestMethod.GET)
    public JsonResult findPhotoAlbumByUserId(@PathVariable String userId){
        return iActivityService.findPhotoAlbumByUserId(userId);
    }

    //活动创建成功之后才进行图片上传(如果是散列的图片而非相册)
    @RequestMapping(value = "/fuckPhotos",method = RequestMethod.POST)
    public JsonResult fileUpLoad(@RequestParam("activityId") String activityId, @RequestParam("uploadFile") MultipartFile[] multipartFiles,String userId){
        return iActivityService.imgUpLoad(activityId,multipartFiles,userId);
    }

    //活动创建成功之后用户如果选择的是使用相册
    @RequestMapping(value = "/usePhotoAlbum",method = RequestMethod.POST)
    public JsonResult usePhotoAlbum(@RequestBody TbActivityPhotoAlbum activityPhotoAlbum){
        return iActivityService.saveActivityAlbum(activityPhotoAlbum);
    }

    @RequestMapping(value = "/findPhotosByActId/{activityId}",method = RequestMethod.GET)
    public JsonResult findPhotosByActId(@PathVariable String activityId){
        return iActivityService.findAllPhotosByActId(activityId);
    }

    //活动上传散列相片
    /*public JsonResult*/

    //路径带参数
    @RequestMapping(value = "/delActivity/{id}",method = RequestMethod.DELETE)
    public JsonResult delActivity(@PathVariable String id){
        return iActivityService.delActivity(id);
    }

    @RequestMapping(value = "updateAvtivity",method = RequestMethod.PUT)
    public JsonResult updateActivity(@RequestBody TbActivity activity){
        return iActivityService.updateActivity(activity);
    }

    @RequestMapping(value = "/findAvtivityById/{id}/{userId}",method = RequestMethod.GET)
    public JsonResult findActivityById(@PathVariable String id,@PathVariable String userId){
        return iActivityService.findActivityById(id,userId);
    }


    //对浏览次数的增加
    @RequestMapping(value = "/updateActiView/{id}",method = RequestMethod.PUT)
    public JsonResult updateActiView(@PathVariable String id){
        return iActivityService.updateActivityViewNum(id);
    }

    //修改活动审核状态
    @RequestMapping(value = "/updateAvtivityOk/{id}/{ok}",method = RequestMethod.PUT)
    public JsonResult updateAvtivityOk(@PathVariable String id,@PathVariable String ok){
        return iActivityService.updateAvtivityOk(id,Long.valueOf(ok));
    }

    @RequestMapping(value = "/findAllActivity",method = RequestMethod.GET)
    public JsonResult findAllActivity(){
        return iActivityService.findAllActivity();
    }

    @RequestMapping(value = "/getNewsActiviyList",method = RequestMethod.GET)
    public JsonResult getNewsActiviyList(){
        return iActivityService.getNewsActiviyList();
    }

    @RequestMapping(value = "/getCityActivityList/{location}",method = RequestMethod.GET)
    public JsonResult getCityActivityList(@PathVariable String location){
        return iActivityService.getCityActivityList(location);
    }

    @RequestMapping(value = "/getHotActivityList",method = RequestMethod.GET)
    public JsonResult getHotActivity(){
        return IGetHotActivityList.getHotActivityList();
    }



}
